package com.wy2.generator.database;

import java.io.Serializable;
import java.util.Properties;

import cn.xo68.core.PropertiesDocument;
import com.wy2.generator.config.DatabaseConsts;

/**
 * @author nnsword
 * @date 2017-12-10 21:58:48
 *
 */
public class JdbcConnectionConfiguration implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private String catalog;
	private String schema;
    
    private String userId;
    private String password;
    private String connectionURL;
    private String driverClass;
    private Properties properties;
    
    
    
    
	
	/**
	 * @return the catalog
	 */
	public String getCatalog() {
		return catalog;
	}
	/**
	 * @param catalog the catalog to set
	 */
	public void setCatalog(String catalog) {
		this.catalog = catalog;
	}
	
	/**
	 * @return the schema
	 */
	public String getSchema() {
		return schema;
	}
	/**
	 * @param schema the schema to set
	 */
	public void setSchema(String schema) {
		this.schema = schema;
	}
	
	/**
	 * @return the userId
	 */
	public String getUserId() {
		return userId;
	}
	/**
	 * @param userId the userId to set
	 */
	public void setUserId(String userId) {
		this.userId = userId;
	}
	/**
	 * @return the password
	 */
	public String getPassword() {
		return password;
	}
	/**
	 * @param password the password to set
	 */
	public void setPassword(String password) {
		this.password = password;
	}
	/**
	 * @return the connectionURL
	 */
	public String getConnectionURL() {
		return connectionURL;
	}
	/**
	 * @param connectionURL the connectionURL to set
	 */
	public void setConnectionURL(String connectionURL) {
		this.connectionURL = connectionURL;
	}
	/**
	 * @return the driverClass
	 */
	public String getDriverClass() {
		return driverClass;
	}
	/**
	 * @param driverClass the driverClass to set
	 */
	public void setDriverClass(String driverClass) {
		this.driverClass = driverClass;
	}
	
    public void addProperty(String name, String value) {
        properties.setProperty(name, value);
    }

    public String getProperty(String name) {
        return properties.getProperty(name);
    }

    public Properties getProperties() {
        return properties;
    }
    
    
	
	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return "JdbcConnectionConfiguration [catalog=" + catalog + ", schema=" + schema + ", userId=" + userId
				+ ", password=" + password + ", connectionURL=" + connectionURL + ", driverClass=" + driverClass
				+ ", properties=" + properties + "]";
	}
	/**
	 * 
	 */
	public JdbcConnectionConfiguration() {
		super();
		properties = new Properties();
	}
    
    /**
     * 从属性对象中架构配置
     * @date 2017-12-17 15:20:27
     * @param properties
     */
	public void load(PropertiesDocument properties) {
		this.setCatalog(properties.getProperty(DatabaseConsts.CONFIG_CONNECT_CATALOG));
		this.setSchema(properties.getProperty(DatabaseConsts.CONFIG_CONNECT_SCHEMA));
		this.setDriverClass(properties.getProperty(DatabaseConsts.CONFIG_CONNECT_DRIVER_CLASS));
		this.setConnectionURL(properties.getProperty(DatabaseConsts.CONFIG_CONNECT_CONNECTION_URL));
		this.setUserId(properties.getProperty(DatabaseConsts.CONFIG_CONNECT_USER_ID));
		this.setPassword(properties.getProperty(DatabaseConsts.CONFIG_CONNECT_PASSWORD));
	}
	

}
